import os
# help(os)

def countType():
    '计算当前文件夹下各类型数量'
    typeDict = dict()

    files = os.listdir(os.getcwd())
    for each in files:
        if os.path.isdir(each):
            typeDict.setdefault('文件夹', 0)
            typeDict['文件夹'] += 1
        else:
            ext = os.path.splitext(each)[1]
            typeDict.setdefault(ext, 0)
            typeDict[ext] += 1

    for each in typeDict.keys():
        print('该文件夹下共有[%s]类型文件%d个' % (each, typeDict[each]))

# countType()

def countSize():
    '计算当前文件夹下各文件大小'
    sizeDict = dict()
    files = os.listdir(os.getcwd())
    for each in files:
        if os.path.isfile(each):
            size = os.path.getsize(each)
            sizeDict[each] = size

    for each in sizeDict:
        print('%s[%dBytes]' % (each,sizeDict[each]))
# countSize()


def countVideo():
    path = '/Users/lyc/Documents/video/小甲鱼零基础入门学习Python(全87集)/00-42'
    files = os.listdir(path)
    vList = open('vList.txt','w')
    targets = ['.mp4','.avi','.rmvb']
    for each in files:
        ext = os.path.splitext(each)[1]
        if ext in targets:
            vList.write(path+ os.sep + each + os.linesep)
        if os.path.isdir(each):
            countVideo()
            os.chdir(os.pardir)

    vList.close()
countVideo()